/**
 * @(#) CreditCardProxy.as
 *
 * @date		2009. 04. 23.
 * @version		1.0
 * @author		Jo,Chang Hun
 * @description	 연말정산  - Proxy
 * 				 기타소득공제 관리 
 */
package com.skt.common_hr.yearadjustment.model
{
	import com.skt.common_hr.common.PsHrAlert;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.yearadjustment.model.vo.CreditCardVO;
	import com.wcl.utils.Hourglass;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;

	public class CreditCardProxy extends CommonProxy
	{
		public static const NAME:String = "CreditCardProxy";

		
		public static const LOAD_CREDITCARD_COMPLETE:String = "loadCreditCardComplete";
		public static const LOAD_CREDITCARD_FAILED:String = "loadCreditCardFailed";
		public static const SAVE_CREDITCARD_COMPLETE:String = "saveCreditCardComplete";
		public static const SAVE_CREDITCARD_FAILED:String = "saveCreditCardFailed";

		public var msgStr:String;
		
		public var creditCardList:ArrayCollection = new ArrayCollection();
		

		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function CreditCardProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		
		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param pernr 사번
		 * @return void
		 */
		public function load(pernr:String, year:String):void
		{
			var param:Object = new Object();
			param["I_YEAR"] = year;
			param["I_PERNR"] = pernr;
			param["I_YEAGBN"] = "03";		//E1: 연금보험료
			param["I_PROC_TYPE"] = "D";		//D:조회, S:저장
			loadData("Z_HR_0085_NEW", param, result, fault);
		}
		
		public function save(parnr:String, year:String, otherArr:Array):void{
			var param:Object = new Object();
			param["I_YEAR"] = year;
			param["I_PERNR"] = parnr;
			param["I_YEAGBN"] = "03";		//E1: 연금보험료
			param["I_PROC_TYPE"] = "S";		//D:조회, S:저장
			var tables:Object = new Object();
			tables["ITAB2"] = otherArr;
			saveData("Z_HR_0085_NEW", param, tables, saveResult, saveFault); 
		}
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		public function result(event:ResultEvent):void
		{
			if(retCode==0) {  
				creditCardList = parseCreditCardList(event.result.ITAB2);
				facade.sendNotification(LOAD_CREDITCARD_COMPLETE, this);
			}
			else {
				msgStr = event.result["RETTEXT"];
				facade.sendNotification(LOAD_CREDITCARD_FAILED, this);
			}
		}
		
		/**
		 * 서버에서 오류가 발생했을 처리
		 * 
		 * @param
		 * @return void
		 */
		private function fault(event:FaultEvent):void
		{
			msgStr = event.fault.faultString;
			facade.sendNotification(LOAD_CREDITCARD_FAILED, this);
		}
		
		public function saveResult(event:ResultEvent):void
		{
			if(retCode==0) {  
				facade.sendNotification(SAVE_CREDITCARD_COMPLETE, this);
			}
			else {
				msgStr = event.result["RETTEXT"];
				facade.sendNotification(SAVE_CREDITCARD_FAILED, this);
			}
		}
		
		/**
		 * 서버에서 오류가 발생했을 처리
		 * 
		 * @param
		 * @return void
		 */
		private function saveFault(event:FaultEvent):void
		{
			Hourglass.remove();
			msgStr = event.fault.faultString;
			facade.sendNotification(SAVE_CREDITCARD_FAILED, this);
		}
		
		
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Parsing functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 개인정보
		 * 
		 * @param
		 * @return 특별공제 보험료 Value Object
		 */
		private function parseCreditCardList(arr:ArrayCollection):ArrayCollection
		{
			var returnArr:ArrayCollection = new ArrayCollection();
			for each(var rec:Object in arr){
				var vo:CreditCardVO = new CreditCardVO();
				vo.SEQNO	= rec["SEQNO"];
				vo.REGNO	= rec["REGNO"];
				vo.SUBTY	= rec["SUBTY"];
				vo.OBJPS	= rec["OBJPS"];
				vo.ENAME	= rec["ENAME"];
				vo.DPTYP	= rec["DPTYP"];
				vo.DPTYPT	= rec["DPTYPT"];
				vo.HNDID	= rec["HNDID"];
				vo.DPTID	= rec["DPTID"];
				vo.YEASUB	= rec["YEASUB"];
				vo.YEASTX	= rec["YEASTX"];
				vo.AMT11	= rec["AMT11"];
				vo.AMT12	= rec["AMT12"];
				vo.AMT13	= rec["AMT13"];
				vo.AMT14	= rec["AMT14"]; 
				vo.AMT21	= rec["AMT21"]; 
				vo.AMT22	= rec["AMT22"];
				vo.AMT23	= rec["AMT23"]; 
				vo.AMT24	= rec["AMT24"];
				//2012.12.28 j.t 추가
				vo.TRDCAN	= rec["TRDCAN"];
				vo.TRDCAO	= rec["TRDCAO"]; 
				vo.TRDCDN	= rec["TRDCDN"]; 
				vo.TRDCDO	= rec["TRDCDO"];
				vo.TRDDBN	= rec["TRDDBN"]; 
				vo.TRDDBO	= rec["TRDDBO"];
				
				
				//if(String("3,6,7,8").indexOf(vo.DPTYP)<0  || vo.SUBTY=="" || (vo.DPTYP=="3" && vo.DPTID=="X") || ( vo.SUBTY == '11' || vo.SUBTY == '12' ) ) {	// 제외조건
				//20120112
				//if( (String("6,7,8").indexOf(vo.DPTYP)<0 && vo.DPTID=="X")  || vo.SUBTY=="" ) {	// 제외조건  
				if( (String("6,7,8").indexOf(vo.DPTYP)<0)  || vo.SUBTY=="" ) {	// 제외조건
					returnArr.addItem(vo);
				}
			}
			
			return returnArr;
		}
		
	}
}